package dao

import (
	"fmt"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

// 全局的数据库对象
var (
	DB *gorm.DB
)

func InitMySQL()(err error){
	dsn := "root:123456@tcp(139.196.194.194:3306)/test1?charset=utf8mb4&parseTime=True&loc=Local"
	DB,err = gorm.Open("mysql",dsn)
	if err != nil{
		fmt.Println("连接失败")
		return
	}
	err = DB.DB().Ping()  // 测试连通性
	return
}
